import java.io.*;
import java.util.Scanner;

/*
 ID: ning yusui
 LANG: JAVA
 TASK: stamps
 */

public class stamps {
    Scanner in;
    PrintWriter out;

    public stamps() throws IOException {
        in = new Scanner(new File(this.getClass().getName() + ".in"));
        out = new PrintWriter(new BufferedWriter(new FileWriter(this.getClass().getName() +
                ".out")));
    }

    private void work() {
        int k = in.nextInt();
        int n = in.nextInt();
        int cents[] = new int[n];
        int maxCent = 10000;
        for (int i = 0; i < n; i++) {
            cents[i] = in.nextInt();
            if (maxCent < cents[i]) maxCent = cents[i];
        }
        int cnt[] = new int[maxCent * k + 1];
        cnt[0] = 0;
        int j = 0;
        for (; cnt[j] > 0 || j == 0; j++) {
            if (cnt[j] < k) {
                for (int cent : cents) {
                    int dst = j + cent;
                    if (cnt[dst] > 0) {
                        cnt[dst] = Math.min(cnt[j] + 1, cnt[dst]);
                    } else {
                        cnt[dst] = cnt[j] + 1;
                    }
                }
            }
        }
        out.println(j - 1);
        out.flush();
        out.close();
    }


    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
        new stamps().work();
        System.out.println(System.currentTimeMillis() - start + "ms");
    }
}
